package com.lcredu.springbootusersys.config;

import com.lcredu.springbootusersys.servlet.Filter_;
import com.lcredu.springbootusersys.servlet.Listener_;
import com.lcredu.springbootusersys.servlet.Servlet_;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.ServletRegistration;
import java.util.Arrays;

/**
 * @author 黎长容
 * @date 2025-08-17 16:55
 */

@SuppressWarnings("all")
/**
 * 配置类注解，用于标识一个类作为Spring配置类
 *
 * @param proxyBeanMethods 设置是否对@Bean方法进行代理，默认为true。
 *                         当设置为true时，Spring会代理@Bean方法以确保单例bean的正确性；
 *                         当设置为false时，Spring不会代理@Bean方法，提高性能但需要开发者自行保证bean的作用域正确性。
 * @return 返回一个配置类实例
 */
@Configuration(proxyBeanMethods = true)
public class RegisterConfig_ {

    @Bean
    public ServletRegistrationBean servlet_() {
        Servlet_ servlet = new Servlet_();
        return new ServletRegistrationBean(servlet, "/servlet01", "/servlet02");
    }

    @Bean
    public FilterRegistrationBean filter_() {
        Filter_ filter = new Filter_();
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(filter);
        filterRegistrationBean.setUrlPatterns(Arrays.asList("/css/*", "/images/*"));
        return filterRegistrationBean;
    }

    @Bean
    public ServletListenerRegistrationBean listener_() {
        Listener_ listener = new Listener_();
        return new ServletListenerRegistrationBean(listener);
    }


}
